from math import sqrt
from OpenGL.GL import *

Vector3D = GLfloat * 3

class Vector3D(object):

	def __init__(self, x, y, z,w=0):
		self.x = float(x)
		self.y = float(y)
		self.z = float(z)
		self.w = float(w)

	def __add__(self, v):
		return Vector3D(self.x+v.x, self.y+v.y, self.z+v.z)

	def __sub__(self, v):
		return Vector3D(self.x-v.x, self.y-v.y, self.z-v.z)

	def __mul__(self, v):
		return Vector3D(self.x*v.x, self.y*v.y, self.z*v.z)

	def __str__(self):
		return "(%s,%s,%s)" % (self.x,self.y,self.z)

	def __div__(self, v):
		return Vector3D(self.x/v.x, self.y/v.y, self.z/v.z)

	def __mod__(self, v):
		return self.cross(v)

	def length(self):
		return sqrt(self.x**2 + self.y**2 + self.z**2)

	def cross(self, v):
		return Vector3D(self.y * v.z - v.y * self.z,
                                v.x * self.z - self.x - v.z,
                                self.x * v.y - v.x - self.y)

	def dot(self, v):
		return Vector3D(self.x * v.x + self.y * v.y + self.z * v.z)

	def normalize(self):
		return Vector3D(self.x / self.length(),self.y / self.length(), self.z / self.length())

	def scale(self,s):
		return Vector3D(self.x * s,self.y * s, self.z * s)



